import {createRouter, createWebHistory} from "vue-router";
import Home from "../views/Home.vue";

const routes = [
    {
        path: '/',
        redirect: '/index'
    }, {
        path: "/",
        name: "Home",
        component: Home,
        children: [
            {
                path: "/index",
                name: "index",
                meta: {
                    title: '首页'
                },
                component: () => import (
                /* webpackChunkName: "index" */
                "../views/index.vue")
            },{
                path: "/businessManage",
                name: "businessManage",
                meta: {
                    title: '企业列表'
                },
                component: () => import (
                /* webpackChunkName: "businessManage" */
                "../views/businessManage.vue")
            },{
                path: "/businessExamine",
                name: "businessExamine",
                meta: {
                    title: '企业审核'
                },
                component: () => import (
                /* webpackChunkName: "businessExamine" */
                "../views/businessExamine.vue")
            },{
                path: "/agreementManage",
                name: "agreementManage",
                meta: {
                    title: '服务者协议'
                },
                component: () => import (
                /* webpackChunkName: "agreementManage" */
                "../views/agreementManage.vue")
            },{
                path: "/serveManage",
                name: "serveManage",
                meta: {
                    title: '服务者管理'
                },
                component: () => import (
                /* webpackChunkName: "serveManage" */
                "../views/serveManage.vue")
            },{
                path: "/personManage",
                name: "personManage",
                meta: {
                    title: '个体商户管理'
                },
                component: () => import (
                /* webpackChunkName: "personManage" */
                "../views/personManage.vue")
            },{
                path: "/financeManage",
                name: "financeManage",
                meta: {
                    title: '打款审核'
                },
                component: () => import (
                /* webpackChunkName: "financeManage" */
                "../views/financeManage.vue")
            },{
                path: "/financeList",
                name: "financeList",
                meta: {
                    title: '结算单列表'
                },
                component: () => import (
                /* webpackChunkName: "financeList" */
                "../views/financeList.vue")
            },{
                path: "/invoiceManage",
                name: "invoiceManage",
                meta: {
                    title: '发票管理'
                },
                component: () => import (
                /* webpackChunkName: "invoiceManage" */
                "../views/invoiceManage.vue")
            },{
                path: "/invoiceManages",
                name: "invoiceManages",
                meta: {
                    title: '发票管理'
                },
                component: () => import (
                /* webpackChunkName: "invoiceManage" */
                "../views/invoiceManages.vue")
            },{
                path: "/invoicePerson",
                name: "invoicePerson",
                meta: {
                    title: '个体工商户发票管理'
                },
                component: () => import (
                /* webpackChunkName: "invoicePerson" */
                "../views/invoicePerson.vue")
            },{
                path: "/taskManage",
                name: "taskManage",
                meta: {
                    title: '任务管理'
                },
                component: () => import (
                /* webpackChunkName: "taskManage" */
                "../views/taskManage.vue")
            },{
                path: "/setting",
                name: "setting",
                meta: {
                    title: '账户设置'
                },
                component: () => import (
                /* webpackChunkName: "setting" */
                "../views/setting.vue")
            },{
                path: "/taskManageDel",
                name: "taskManageDel",
                meta: {
                    title: '任务明细'
                },
                component: () => import (
                /* webpackChunkName: "taskManageDel" */
                "../views/taskManageDel.vue")
            },{
                path: "/personManageDel",
                name: "personManageDel",
                meta: {
                    title: '个体户详情'
                },
                component: () => import (
                /* webpackChunkName: "personManageDel" */
                "../views/personManageDel.vue")
            }, {
                path: '/settlementDels',
                name: 'settlementDels',
                meta: {
                    title: '无感发薪结算单详情'
                },
                component: () => import (/* webpackChunkName: "settlementDels" */
                '../views/settlementDels.vue')
            }, {
                path: "/settlements",
                name: "settlements",
                meta: {
                    title: '无感发薪结算单'
                },
                component: () => import (
                /* webpackChunkName: "settlements" */
                "../views/settlements.vue")
            }, {
                path: "/recharge",
                name: "recharge",
                meta: {
                    title: '充值记录'
                },
                component: () => import (
                /* webpackChunkName: "recharge" */
                "../views/recharge.vue")
            }, {
                path: "/operationLog",
                name: "operationLog",
                meta: {
                    title: '操作日志'
                },
                component: () => import (
                /* webpackChunkName: "operationLog" */
                "../views/operationLog.vue")
            }, {
                path: "/loginLog",
                name: "loginLog",
                meta: {
                    title: '登录日志'
                },
                component: () => import (
                /* webpackChunkName: "loginLog" */
                "../views/loginLog.vue")
            }, {
                path: "/surplus",
                name: "surplus",
                meta: {
                    title: '账户管理'
                },
                component: () => import (
                /* webpackChunkName: "recharge" */
                "../views/surplus.vue")
            }, {
                path: "/examine",
                name: "examine",
                meta: {
                    title: '审批记录'
                },
                component: () => import (
                /* webpackChunkName: "examine" */
                "../views/examine.vue")
            }, {
                path: "/taxSource",
                name: "taxSource",
                meta: {
                    title: '税源地设置'
                },
                component: () => import (
                /* webpackChunkName: "taxSource" */
                "../views/taxSource.vue")
            }, {
                path: "/taxMannge",
                name: "taxMannge",
                meta: {
                    title: '税源地管理'
                },
                component: () => import (
                /* webpackChunkName: "taxMannge" */
                "../views/taxMannge.vue")
            }, {
                path: "/project",
                name: "project",
                meta: {
                    title: '项目管理',
                },
                component: () => import (
                /* webpackChunkName: "project" */
                "../views/project.vue")
            }, {
                path: "/permission",
                name: "permission",
                meta: {
                    title: '员工管理',
                },
                component: () => import (
                /* webpackChunkName: "project" */
                "../views/permission.vue")
            }, {
                path: "/byRole",
                name: "byRole",
                meta: {
                    title: '角色管理',
                },
                component: () => import (
                /* webpackChunkName: "project" */
                "../views/byRole.vue")
            }
        ]
    }, {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import (
        /* webpackChunkName: "login" */
        "../views/Login.vue")
    }, {
        path: "/register",
        name: "register",
        meta: {
            title: '注册'
        },
        component: () => import (
        /* webpackChunkName: "register" */
        "../views/register.vue")
    }, {
        path: "/:pathMatch(.*)*",
		meta: {
			title: '404页面不存在'
		},
        component: () => import (
        /* webpackChunkName: "login" */
        "../views/404.vue")
    }
];

const router = createRouter({
    // history: createWebHistory('/crm/'),
    history: createWebHistory(),
    routes
});

console.log(router)

router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title}`;
    const role = localStorage.getItem('linggong_token');
    if (!role && to.path !== '/login') {
        next('/login');
    }else {
        next();
    }
});

export default router;